<?php
require_once("Config.php");
$messageFlag = '0';
$showXContent = 'theIntro_';
if($_GET['action']=='saveIntro'){
  $sql = "update news set content='".$_POST['introContent']."' where newsType=2 and title='menus_intro'";
  if(mysql_query($sql)){
    $sessionMessage ="Save content success!";
  }else{
    $sessionMessage = 'Save conent failure!';
  }
  $messageFlag='1';
}

if($_GET['action']=='saveIntro'){
  $sql = "update news set content='".$_POST['cocktailContent']."' where newsType=2 and title='menus_cocktail'";
  if(mysql_query($sql)){
    $sessionMessage ="Save INTRO content success!";
  }else{
    $sessionMessage = 'Save INTRO conent failure!';
  }
  $messageFlag='1';
}


if($_GET['action']=='saveWhisky'){
  $sql = "update news set content='".$_POST['whiskyContent']."' where newsType=2 and title='menus_whisky'";
  if(mysql_query($sql)){
    $sessionMessage ="Save whisky content success!";
  }else{
    $sessionMessage = 'Save WHISKY conent failure!';
  }
  $messageFlag='1';
}
if(isset($_GET['showXContent'])){
  $showXContent = $_GET['showXContent'];
}

if($_GET['action']=='saveFood'){
  $sql = "update news set content='".$_POST['foodContent']."' where newsType=2 and title='menus_food'";
  if(mysql_query($sql)){
    $sessionMessage ="Save FOOD content success!";
  }else{
    $sessionMessage = 'Save FOOD conent failure!';
  }
  $messageFlag='1';
}

if($_GET['action']=='saveLunch'){
  $sql = "update news set content='".$_POST['lunchContent']."' where newsType=2 and title='menus_lunch'";
  if(mysql_query($sql)){
    $sessionMessage ="Save content success!";
  }else{
    $sessionMessage = 'Save conent failure!';
  }
  $messageFlag='1';
}

$sql = "Select * From news where newsType=2";
$result = mysql_query($sql);
if(!$result){
  echo 'Errow account when query the database.';
  exit();
}
while($row = mysql_fetch_array($result)){
      
    if($row['title']=='menus_intro'){
      $menus_intro = $row['content'];
    }  
    if($row['title']=='menus_cocktail'){
      $menus_cocktail = $row['content'];
    }
    if($row['title']=='menus_whisky'){
      
      $menus_whisky = $row['content'];
    }
    if($row['title']=='menus_food'){
      $menus_food = $row['content'];
    }
    if($row['title']=='menus_lunch'){
      $menus_lunch=$row['content'];
    }
  
}

?>
<html>
  <head>
    <title>
      Add User !
    </title>
    <link href="css/admin-common.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="../js/jquery.js">
    </script>
   
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script>
    
  </head>
  <body>
  <input type="hidden" name='messageFlag' id='messageFlag' value='<?php echo $messageFlag ?>'/>
  <input type="hidden" name="showXContent" id="showXContent" value="<?php echo $showXContent?>"
    <h3>Content Management : About Us</h3>
    <hr/>
    <!--Here is the message from server when page load-->
    <div id="sessionMessage">
      <?php echo $sessionMessage?>
    </div>
    <!--Session Message End-->
    
      <p class="subLinks">
      <label>
        <Strong><a href="#" id='theIntro'><span>Intro</span></a></Strong>
      </label> |
     <label>
        <Strong><a href="#" id='theCocktail'><span>Cocktail</span></a></Strong>
      </label> |
      <label>
        <Strong><a href="#" id='theWhisky'><span>Whisky</span></a></Strong>
      </label> |
      <label>
        <Strong><a href="#" id='theFood'><span>Food</span></a></Strong>
      </label> |
      <label>
        <Strong><a href="#" id='theLunch'><span>Lunch</span></a></Strong>
      </label>
    </p>
    
    
    <!--Add User Form-->
    <form action="?action=saveIntro&showXContent=theIntro" method="post" id="theIntro_" name='theIntro_'>
    <strong>Introduction of menus goes here:</strong>
      <textarea class="ckeditor" cols="80" id="introContent" name="introContent" rows="20"><?php echo $menus_intro ?></textarea>
      <p>
        <label>
          <span>&nbsp;</span>
          <button class="btn btn-style-1" type="submit">
            <b><b>Save</b></b>
          </button>
        </label>
      </p>
    </form>
    
    <form action="?action=saveCocktail&showXContent=theCocktail_" method="post" id="theCocktail_" name='theCocktail_'>
    <strong>Cocktail Menu:</strong>  
      <textarea class="ckeditor" cols="80" id="cocktailContent" name="cocktailContent" rows="20"><?php echo $menus_cocktail ?></textarea>
      <p>
        <label>
          <span>&nbsp;</span>
          <button class="btn btn-style-1" type="submit">
            <b><b>Save</b></b>
          </button>
        </label>
      </p>
    </form>
    
    <form action="?action=saveWhisky&showXContent=theWhisky_" method="post" id="theWhisky_" name="theWhisky_">
    <strong>Whisky Menu:</strong> 
      <textarea class="ckeditor" cols="80" id="whiskyContent" name="whiskyContent" rows="20"><?php echo $menus_whisky ?></textarea>
      <p>
        <label>
          <span>&nbsp;</span>
          <button class="btn btn-style-1" type="submit">
            <b><b>Save</b></b>
          </button>
        </label>
      </p>
    </form>
    
    <form action="?action=saveFood&showXContent=theFood_" method="post" name='theFood_' id='theFood_'>
    <strong>Food Menu:</strong>
      <textarea class="ckeditor" cols="80" id="foodContent" name="foodContent" rows="20"><?php echo $menus_food ?></textarea>
      <p>
        <label>
          <span>&nbsp;</span>
          <button class="btn btn-style-1" type="submit">
            <b><b>Save</b></b>
          </button>
        </label>
      </p>
    </form>
    
    <form action="?action=saveLunch&showXContent=theLunch_" method="post" name='theLunch_' id='theLunch_'>
    <strong>Lunch Menu:</strong>
      <textarea class="ckeditor" cols="80" id="lunchContent" name="lunchContent" rows="20"><?php echo $menus_lunch ?></textarea>
      <p>
        <label>
          <span>&nbsp;</span>
          <button class="btn btn-style-1" type="submit">
            <b><b>Save</b></b>
          </button>
        </label>
      </p>
    </form>
  </body>
  <script type="text/javascript">
    var app={
      init: function() {
     app.showTheContent($('#showXContent').val());
      
    
      
       /* $('form').css('display','none');
        $('#theIntro_').css('display','');
        $($('.subLinks label a span')[0]).addClass('currentItem');*/
        $($('.subLinks label a')).bind('click', function() {
       
          var items = $('.subLinks label a span');

          for(var i=0;i<items.length;i++) {
            if($($(items[i]).parent()).attr('id')==$(this).attr('id')) {
              app.showTheContent($(this).attr('id')+'_');
              /*$(items[i]).addClass('currentItem');
              $('form').css('display','none');
              $('#'+$($(items[i]).parent()).attr('id')+'_').css('display','');*/
            }
          }
          return;
        })

      },
      showTheContent:function(theFormId){ 
      $('.subLinks label a span').removeClass('currentItem');
          $('form').css('display','none');
          $('#'+theFormId).css('display','');
        $(('#'+theFormId.split('_')[0]+' span')).addClass('currentItem');
      }

    }
  </script>
   <script type="text/javascript" src="js/common.js">
    </script>
</html>
